//
//  HXLTravelGuidesViewController.m
//  On The Load
//
//  Created by 晓琳 on 15/11/6.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "HXLTravelGuidesViewController.h"
#import "DataHandle.h"
#import "TravelPlan.h"
#import "HXLGuideCollectionViewCell.h"
#import "BaseCollectionView.h"
#import "HXLLeavesModel.h"
#import "HXLCityModel.h"
#import "AppTools.h"
#import <MBProgressHUD.h>


@interface HXLTravelGuidesViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,PushDetailViewControllerDelegate,MBProgressHUDDelegate>
@property (nonatomic, strong) NSMutableArray *overseasArray;
@property (nonatomic, strong) NSMutableArray *idArray;


@end

@implementation HXLTravelGuidesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSArray *areas2Array = [[DataHandle shareDataHandle].finDic objectForKey:@"areas2"];
    self.idArray = [NSMutableArray array];
    self.overseasArray = [NSMutableArray array];
    
    
    for (HXLCityModel *model in areas2Array) {
        
        for (HXLLeavesModel *smallModel in model.leavesArray) {
            [self.overseasArray addObject:smallModel];
        }
    }

    NSLog(@"cccc = %ld",self.countryIdArray.count);

    for (HXLLeavesModel *plan1 in _overseasArray) {
        
        for (TravelPlan *plan2 in _countryIdArray) {
            
            [self.idArray removeAllObjects];
            if ([plan1.countryId isEqual:plan2.countryId]) {
                //国外的id
                [self.idArray addObject:plan2.countryId];
            }
            
        }
        
    }
    NSLog(@"id = %ld",self.idArray.count);
    
    if (self.idArray.count == 0) {
    
        MBProgressHUD *hub = [[MBProgressHUD alloc] init];
        hub.labelText = @"暂时没有您需要的数据,小编正在努力";
        hub.mode = MBProgressHUDModeText;
        [self.view addSubview:hub];
        hub.delegate = self;
        
        [hub show:YES];
    }else {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(300, 600);
    layout.sectionInset = UIEdgeInsetsMake(30, 30, 30, 30);
    

     BaseCollectionView *guideCollectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:layout];
    guideCollectionView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:guideCollectionView];
    guideCollectionView.delegate =self;
    guideCollectionView.dataSource = self;
        guideCollectionView.showsVerticalScrollIndicator = YES;
    
    [guideCollectionView registerClass:[HXLGuideCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    }
    
}

- (void) hudWasHidden:(MBProgressHUD *)hud {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void) getAFNData:(NSNumber *)countryId {
    //数据请求
    NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
    NSString *country = [numberFormatter stringFromNumber:countryId];
    [AppTools getAFN: [NSString stringWithFormat:@"http://travelbox-interface.xyz.cn/trip/areas/get?areaIds=%@&uid=suitcase&ts=1447292248796&sig=4a9676258ff1991f25d0817407aa69a8 ",country] andpara:nil andBlock:^(id result) {
//http://travelbox-interface.xyz.cn/trip/areas/get?areaIds=%103&uid=suitcase&ts=1447292248796&sig=4a9676258ff1991f25d0817407aa69a8
        //http://travelbox-interface.xyz.cn/trip/areas/get?areaIds=103&uid=suitcase&ts=1447292248796&sig=4a9676258ff1991f25d0817407aa69a8
        NSDictionary *dic = result;
        NSDictionary *responseDic = [dic objectForKeyedSubscript:@"response"];
        NSArray *array = [responseDic objectForKey:@"areaDetails"];
        
    } andfailBlock:^(id result) {
        
        
    }];
    
    

    
}

//实现button协议方法,进入详情
- (void)pushDetailViewcontroller:(NSInteger)tag {
    
//    if (tag == ||tag== || tag ||) {
//        <#statements#>
//    }
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HXLGuideCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    return cell;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    NSLog(@"ccc = %ld",self.idArray.count);
    return self.idArray.count;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
